namespace SimpleWebServices.Web.Mvc
{
    using System;
    using System.Net.Mime;
    using SimpleWebServices;
    using Xunit;

    public sealed class ContentNegotiationAttributeFacts
    {
        [Fact]
        public void typedef()
        {
            Assert.True(new ObjectExpectations<ContentNegotiationAttribute>()
                .DerivesFrom<Attribute>()
                .IsConcreteClass()
                .IsSealed()
                .NoDefaultConstructor()
                .IsDecoratedWith<AttributeUsageAttribute>()
                .Result);
        }

        [Fact]
        public void ctor()
        {
            Assert.NotNull(new ContentNegotiationAttribute());
        }

        [Fact]
        public void ctor_string_string()
        {
            Assert.NotNull(new ContentNegotiationAttribute(".example", "text/example"));
        }

        [Fact]
        public void ctor_stringEmpty_string()
        {
            Assert.Throws<ArgumentOutOfRangeException>(() => new ContentNegotiationAttribute(string.Empty, "text/example"));
        }

        [Fact]
        public void ctor_stringNull_string()
        {
            Assert.Throws<ArgumentNullException>(() => new ContentNegotiationAttribute(null, "text/example"));
        }

        [Fact]
        public void ctor_string_stringEmpty()
        {
            Assert.Throws<ArgumentOutOfRangeException>(() => new ContentNegotiationAttribute(".example", string.Empty));
        }

        [Fact]
        public void ctor_string_stringNull()
        {
            Assert.Throws<ArgumentNullException>(() => new ContentNegotiationAttribute(".example", null));
        }

        [Fact]
        public void prop_Extension()
        {
            Assert.True(new PropertyExpectations(typeof(ContentNegotiationAttribute).GetProperty("Extension"))
                .DefaultValueIs("html")
                .ArgumentNullException()
                .Set("example")
                .Set(".example")
                .Result);
        }

        [Fact]
        public void prop_MediaTypes()
        {
            Assert.True(new PropertyExpectations(typeof(ContentNegotiationAttribute).GetProperty("MediaTypes"))
                .DefaultValueIs("*/*")
                .ArgumentNullException()
                .ArgumentOutOfRangeException(string.Empty)
                .FormatException("example")
                .Set("application/xhtml+xml")
                .Set("*/*, text/*, text/html")
                .Result);
        }

        [Fact]
        public void op_ToContentTypes()
        {
            string expected = "text/example";

            foreach (ContentType actual in new ContentNegotiationAttribute(".example", expected).ToContentTypes())
            {
                Assert.Equal<string>(expected, actual.MediaType);
            }
        }
    }
}